package com.fire.web.modules.all.controller;

import com.fire.web.modules.all.constant.ErrorCodeConstants;
import com.fire.web.modules.all.entity.AjaxResult;
import com.fire.web.modules.all.service.IAllUserService;
import com.fire.web.modules.all.service.ITMitErrorCodeService;
import com.fire.web.modules.sys.controller.UserController;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class AllUserController {
	private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

	@Autowired
	ITMitErrorCodeService errorCodeService;
	@Autowired
	IAllUserService allUserService;
	/**
	 * 增加用户
	 * @param  userid
	 * @return
	 */
	@RequestMapping(value = "/addUser", method = RequestMethod.POST)
	@ResponseBody
	public AjaxResult addUser(@RequestBody String json) {
		LOGGER.info(json);
		AjaxResult ajaxResult = new AjaxResult();
		try {
			ajaxResult = allUserService.addUser(json);
		} catch (Exception e) {
			LOGGER.error("UserController.getuserInfo().error  错误为：", e);
			ajaxResult.setTips("系统内部错误");
			ajaxResult.setMessage("系统内部错误");
			ajaxResult.setStatus(ErrorCodeConstants.INTERNAL_ERROR);
		}
		String tips = errorCodeService.getTips(ajaxResult.getStatus());
		if (StringUtils.isNotBlank(tips)) {
			ajaxResult.setTips("[" + ajaxResult.getStatus() + "]" + tips);
		} else {
			ajaxResult.setTips("[" + ajaxResult.getStatus() + "]" + ajaxResult.getTips());
		}
		return ajaxResult;
	}
}
